package helplib

import "time"

func ReadChannelInTimeMS[T any](ch *chan T, lmtms int) (*T, bool) {
	if lmtms == 0 {
		res := <-*ch
		return &res, true
	} else {
		select {
		case res := <-*ch:
			return &res, true
		case <-time.After(time.Millisecond * time.Duration(lmtms)):
			return nil, false
		}
	}
}

func ClearChannelInTimeMS[T any](ch *chan T, lmtms int) {
	for len(*ch) != 0 {
		ReadChannelInTimeMS(ch, lmtms)
	}
}
